﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationKredit
{
    class Program
    {
        static int ReadIntFromConsole()
        {
            try
            {

                return (Int32.Parse(Console.ReadLine()));
            }
            catch
            {
                Console.WriteLine("Input error");
                return ReadIntFromConsole();
            }

        }
        static Double ReadDoubleFromConsole()
        {
            try
            {

                return (Double.Parse(Console.ReadLine()));
            }
            catch
            {
                Console.WriteLine("Input error");
                return ReadDoubleFromConsole();
            }

        }
        static void Main(string[] args)
        {
            Console.WriteLine("Здраствуйте, введите сумму кредита.");
            double Sum = ReadDoubleFromConsole();
            Console.WriteLine("Введите срок кредита(месяцев).");
            int Count = ReadIntFromConsole();
            DateTime dt = DateTime.Today;
            int Order = 1;
            double payment = Math.Round(Sum / Count, 2);
            Console.WriteLine("# Дата платежа    Сумма платежа");
            
            for(int i=0; i<=Count-1; i++)
            {
                               
                if(dt.DayOfWeek==DayOfWeek.Saturday)
                {

                    DateTime dt2 = dt.AddDays(-1);
                    if (i == 0)
                    {
                        double Fpayment = payment + (Sum - (payment * Count));
                        Console.WriteLine("{0} {1}      {2}", Order, dt2.ToString("dd.MM.yyyy"), Fpayment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                    else
                    {
                        Console.WriteLine("{0} {1}      {2}", Order, dt2.ToString("dd.MM.yyyy"), payment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                }
                else if(dt.DayOfWeek==DayOfWeek.Sunday)
                {
                    DateTime dt2 = dt.AddDays(-2);
                    if (i == 0)
                    {
                        double Fpayment = payment + (Sum - (payment * Count));
                        Console.WriteLine("{0} {1}      {2}", Order, dt2.ToString("dd.MM.yyyy"), Fpayment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                    else
                    {
                        Console.WriteLine("{0} {1}      {2}", Order, dt2.ToString("dd.MM.yyyy"), payment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                }
                else
                {
                    if (i == 0)
                    {
                        double Fpayment = payment + (Sum - (payment * Count));
                        Console.WriteLine("{0} {1}      {2}", Order, dt.ToString("dd.MM.yyyy"), Fpayment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                    else
                    {
                        Console.WriteLine("{0} {1}      {2}", Order, dt.ToString("dd.MM.yyyy"), payment);
                        dt = dt.AddMonths(1);
                        Order++;
                    }
                }
            }
            Console.ReadKey();
        }
    }
}
